package remote{
	
	import entidades.Usuario;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.AsyncToken;
	import mx.rpc.Responder;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.mxml.RemoteObject;
	
	public class UsuarioRemote {
		
		public function exibirUsuario( result:Function ):void{
			var async:AsyncToken = _remote.verificarUsuarioLogado();
			async.addResponder( new Responder( result, defaultFaultHandler ) );
		}
		public function sair( result:Function ):void{
			var async:AsyncToken = _remote.sair();
			async.addResponder( new Responder( result, defaultFaultHandler ) );
		}
		
		
		public function gravarUsuario(result:Function, usuario:Usuario):void{
			var async:AsyncToken = _remote.autenticarUsuario(usuario);
			async.addResponder( new Responder( result, defaultFaultHandler ) );			
		}
		public function obterTiposUsuarioSessao(result:Function):void{
			var async:AsyncToken = _remote.obterTiposUsuarioSessao();
			async.addResponder( new Responder( result, defaultFaultHandler ) );			
		}
				
		//--------------------setup----------------------------//
		private var _remote:RemoteObject;
		
		public function UsuarioRemote(){
			_remote = new RemoteObject();
			_remote.showBusyCursor = true;
			_remote.destination = 'UsuarioService';
		}
		
		private function defaultFaultHandler(e:FaultEvent):void{
//			Alert.show( e.fault.faultString );
			Alert.show("Estamos com problemas no servidor! Tente novamente mais tarde!","Usuário");
		}
		
		private static var _instance:UsuarioRemote;
		public static function getInstance():UsuarioRemote{
			if(_instance == null){
				_instance = new UsuarioRemote();
			}
			return _instance;
		}
	}
}